{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "is_executing": true
    }
   },
   "outputs": [],
   "source": [
    "from gs_quant.instrument import FXVolatilitySwap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.session import GsSession\n",
    "# external users should substitute their client id and secret; please skip this step if using internal jupyterhub\n",
    "GsSession.use(client_id=None, client_secret=None, scopes=('run_analytics'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get list of properties of an fx vol swap\n",
    "FXVolatilitySwap.properties()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "swap = FXVolatilitySwap(pair='GBPUSD', last_fixing_date='3m', buy_sell='Buy')\n",
    "swap.resolve()\n",
    "print(swap.strike_vol*100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#forward starting vol swap\n",
    "fwd_6m6m_swap = FXVolatilitySwap(pair='USDJPY', first_fixing_date='6m', last_fixing_date='1y', buy_sell='Buy')\n",
    "fwd_6m6m_swap.resolve()\n",
    "print(fwd_6m6m_swap.as_dict())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "**Fixing frequency** defaults to 'Daily/Business Days' but many other conventions are supported such as:\n",
    "* 'Daily/All Days'\n",
    "* 'Daily/Holiday'\n",
    "* 'Daily/MonToSat'\n",
    "* 'Daily/Weighted Lagging'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "weighted_swap = FXVolatilitySwap(pair='GBPUSD', last_fixing_date='1y', buy_sell='Buy', fixing_frequency='Daily/Weighted Lagging')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "**Fixing source** defaults to 'WM Company LDN 4pm Mid' but other options include:\n",
    "* 'GS NYC 3PM'\n",
    "* 'WM Company NYC 10am Mid'\n",
    "* 'BFIX LDN 4PM'\n",
    "* 'WMC Company LDN 1pm Mid'\n",
    "\n",
    "We also have bloomberg options as well such as 'BFIX TKO 3pm-m'. \n",
    "We're happy to confirm the syntax if you are looking for a fixing source that is not mentioned here.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "bfix = FXVolatilitySwap(pair='GBPUSD', last_fixing_date='1y', buy_sell='Buy', fixing_source='BFIX LDN 4PM')\n",
    "print(bfix.strike_vol)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "**Strike vol** defaults to ATM but the following solvers are supported:\n",
    "\n",
    "* zero cost vol : price=0\n",
    "* % Vol = {%}N (i.e. '2N')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#zero cost vol\n",
    "zero_swap = FXVolatilitySwap(pair='USDNOK', last_fixing_date='3m', buy_sell='Sell', strike_vol='price=0')\n",
    "zero_swap.resolve()\n",
    "zero_swap.price()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "#1.25*atm\n",
    "swap_25 = FXVolatilitySwap(pair='EURUSD', last_fixing_date='3m', buy_sell='Sell', strike_vol='1.25N')\n",
    "swap_25.resolve()\n",
    "print(swap_25.strike_vol*100)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# current spot\n",
    "swap_spot = FXVolatilitySwap(pair='EURUSD', last_fixing_date='3m', buy_sell='Sell', strike_vol='S')\n",
    "swap_spot.resolve()\n",
    "print(swap_spot.strike_vol*100)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# current spot\n",
    "swap_spot = FXVolatilitySwap(pair='EURUSD', last_fixing_date='3m', buy_sell='Sell', strike_vol='S')\n",
    "swap_spot.resolve()\n",
    "print(swap_spot.strike_vol*100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# current spot\n",
    "swap_spot = FXVolatilitySwap(pair='EURUSD', last_fixing_date='3m', buy_sell='Sell', strike_vol='S')\n",
    "swap_spot.resolve()\n",
    "print(swap_spot.strike_vol*100)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}